package Lab12;

import java.util.*;

import java.io.*;

import java.net.*;

public class exercise_12_4 {

    public static void main(String[] args) throws IOException {

        String content = "";

        try {

            URL url = new URL("https://www.douban.com/robots.txt");

            URLConnection connection = url.openConnection();

            connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");

            InputStream is = connection.getInputStream();

            int count = 0, r;

            while ((r = is.read()) != -1) {


//32 代表空格
                if (r == 32)

                    count++;

            }

            System.out.println("The number of words are " + count);
//            The number of words are 34
        } catch (Exception e) {

            e.printStackTrace();

        }

    }

}